package electricity.WebSocket;

import electricity.WebSocket.DeviceWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class WebSocketDataScheduler {

    @Autowired
    private DeviceWebSocketHandler deviceWebSocketHandler;

    // 每1秒执行一次
    @Scheduled(fixedRate = 1000)
    public void sendDataPeriodically() {
        deviceWebSocketHandler.sendUpdatesToAll();
    }
}
